package com.hyx.api.controller.pc_admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hyx.api.service.pc_admin.IRecycleReceivingAddrService;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
import com.hyx.api.domain.bo.RecycleReceivingAddrBo;
import com.hyx.api.domain.vo.RecycleReceivingAddrVo;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 回收商收货地址Controller
 *
 * @author HK
 * @date 2023-11-18
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/addr")
public class RecycleReceivingAddrController extends BaseController
{
    private final IRecycleReceivingAddrService recycleReceivingAddrService;

    /**
     * 查询回收商收货地址列表
     */
    @PreAuthorize("@ss.hasPermi('api:addr:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecycleReceivingAddrBo bo)
    {
        startPage();
        List<RecycleReceivingAddrVo> list = recycleReceivingAddrService.selectRecycleReceivingAddrList(bo);
        return getDataTable(list);
    }

    /**
     * 导出回收商收货地址列表
     */
    @PreAuthorize("@ss.hasPermi('api:addr:export')")
    @Log(title = "回收商收货地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecycleReceivingAddrBo bo)
    {
        List<RecycleReceivingAddrVo> list = recycleReceivingAddrService.selectRecycleReceivingAddrList(bo);
        ExcelUtil<RecycleReceivingAddrVo> util = new ExcelUtil<>(RecycleReceivingAddrVo.class);
        util.exportExcel(response, list, "回收商收货地址数据");
    }

    /**
     * 获取回收商收货地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:addr:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recycleReceivingAddrService.selectRecycleReceivingAddrById(id));
    }

    /**
     * 新增回收商收货地址
     */
    @PreAuthorize("@ss.hasPermi('api:addr:add')")
    @Log(title = "回收商收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody RecycleReceivingAddrBo bo)
    {
        return toAjax(recycleReceivingAddrService.insertRecycleReceivingAddr(bo));
    }

    /**
     * 修改回收商收货地址
     */
    @PreAuthorize("@ss.hasPermi('api:addr:edit')")
    @Log(title = "回收商收货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody RecycleReceivingAddrBo bo)
    {
        return toAjax(recycleReceivingAddrService.updateRecycleReceivingAddr(bo));
    }

    /**
     * 删除回收商收货地址
     */
    @PreAuthorize("@ss.hasPermi('api:addr:remove')")
    @Log(title = "回收商收货地址", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recycleReceivingAddrService.deleteRecycleReceivingAddrByIds(ids));
    }
}

